﻿//------------------------------------------------------------------------------
// <copyright file="ExcelControllerExtensions.cs" company="David Martos">
//     Copyright (c) David Martos.  All rights reserved.
// </copyright>
// <summary>The Export to Excel controller extension class.</summary>
//------------------------------------------------------------------------------
namespace Dissemination.MVC.Controllers.Extensions
{
   using System.Linq;
   using System.Web.Mvc;

   /// <summary>
   /// Excel controller extensions class.
   /// </summary>
   public static class ExcelControllerExtensions
   {

       //public static ActionResult Excel(this Controller controller, string friendlyName, string fileName, string templateName, string excelWorkSheetName, int rows)
       //{
       //    return new ExcelResult(friendlyName, fileName, templateName, excelWorkSheetName, rows);
       //}

       /// <summary>
       /// Controller Extension: Returns an Excel result constructor for returning values from rows.
       /// </summary>
       /// <param name="controller">This controller.</param>
       /// <param name="friendlyName">Name of the friendly.</param>
       /// <param name="fileName">Excel file name.</param>
       /// <param name="templateName">Name of the template.</param>
       /// <param name="excelWorkSheetName">Excel worksheet name: default: sheet1.</param>
       /// <param name="rows">Excel row values.</param>
       /// <returns>Action result.</returns>
      public static ActionResult Excel(this Controller controller, string friendlyName, string fileName, string templateName, string excelWorkSheetName, IQueryable rows)
      {
         return new ExcelResult(friendlyName, fileName, templateName, excelWorkSheetName, rows);
      }

      /// <summary>
      /// Controller Extension: Excel result constructor for returning values from rows and headers.
      /// </summary>
      /// <param name="controller">This controller.</param>
      /// <param name="friendlyName">Name of the friendly.</param>
      /// <param name="fileName">Excel file name.</param>
      /// <param name="templateName">Name of the template.</param>
      /// <param name="excelWorkSheetName">Excel worksheet name: default: sheet1.</param>
      /// <param name="rows">Excel row values.</param>
      /// <param name="headers">Excel header values.</param>
      /// <returns>Action result.</returns>
      public static ActionResult Excel(this Controller controller, string friendlyName, string fileName, string templateName, string excelWorkSheetName, IQueryable rows, string[] headers)
      {
         return new ExcelResult(friendlyName, fileName, templateName, excelWorkSheetName, rows, headers);
      }

      /// <summary>
      /// Controller Extension: Excel result constructor for returning values from rows and headers and row keys.
      /// </summary>
      /// <param name="controller">This controller.</param>
      /// <param name="friendlyName">Name of the friendly.</param>
      /// <param name="fileName">Excel file name.</param>
      /// <param name="templateName">Name of the template.</param>
      /// <param name="excelWorkSheetName">Excel worksheet name: default: sheet1.</param>
      /// <param name="rows">Excel row values.</param>
      /// <param name="headers">Excel header values.</param>
      /// <param name="rowKeys">Key values for the rows collection.</param>
      /// <returns>Action result.</returns>
      public static ActionResult Excel(this Controller controller, string friendlyName, string fileName, string templateName, string excelWorkSheetName, IQueryable rows, string[] headers, string[] rowKeys)
      {
         return new ExcelResult(friendlyName, fileName, templateName, excelWorkSheetName, rows, headers, rowKeys);
      }
   }
}